/*
 * FaceCat图形通讯框架
 * 著作权编号:2015SR229355+2020SR0266727
 * 上海卷卷猫信息技术有限公司
 */

using System;

namespace FaceCat {
    /// <summary>
    /// 日期标题
    /// </summary>
    public class DateTitle : FCButton {
        /// <summary>
        /// 创建日期标题
        /// </summary>
        /// <param name="calendar">日历视图</param>
        public DateTitle(FCCalendar calendar) {
            m_calendar = calendar;
            setBackColor(FCColor.None);
            setBorderColor(FCColor.None);
            setFont(new FCFont("Default", 22, true, false, false));
            setSize(new FCSize(180, 30));
        }

        /// <summary>
        /// 日历
        /// </summary>
        public FCCalendar m_calendar;

        /// <summary>
        /// 获取日历
        /// </summary>
        public virtual FCCalendar getCalendar()
        {
            return m_calendar;
        }

        /// <summary>
        /// 设置日历
        /// </summary>
        public virtual void setCalendar(FCCalendar value)
        {
            m_calendar = value;
        }

        /// <summary>
        /// 获取视图类型
        /// </summary>
        /// <returns>视图类型</returns>
        public override String getViewType() {
            return "DateTitle";
        }

        /// <summary>
        /// 触摸点击方法
        /// </summary>
        /// <param name="touchInfo">触摸信息</param>
        public override void onClick(FCTouchInfo touchInfo) {
            base.onClick(touchInfo);
            if (m_calendar != null) {
                FCCalendarMode mode = m_calendar.getMode();
                //日
                if (mode == FCCalendarMode.Day) {
                    m_calendar.setMode(FCCalendarMode.Month);
                }
                //月
                else if (mode == FCCalendarMode.Month) {
                    m_calendar.setMode(FCCalendarMode.Year);
                }
                m_calendar.update();
                m_calendar.invalidate();
            }
        }

        /// <summary>
        /// 重绘前景方法
        /// </summary>
        /// <param name="paint">绘图对象</param>
        /// <param name="clipRect">裁剪区域</param>
        public override void onPaintForeground(FCPaint paint, FCRect clipRect) {
            if (m_calendar != null) {
                int width = getWidth(), height = getHeight();
                FCFont font = getFont();
                String text = "";
                FCCalendarMode mode = m_calendar.getMode();
                //日
                if (mode == FCCalendarMode.Day) {
                    CMonth month = m_calendar.getMonth();
                    text = month.getYear().ToString() + "年" + month.getMonth().ToString() + "月";
                }
                //月
                else if (mode == FCCalendarMode.Month) {
                    text = m_calendar.getMonthDiv().getYear().ToString() + "年";
                }
                //年
                else if (mode == FCCalendarMode.Year) {
                    int startYear = m_calendar.getYearDiv().getStartYear();
                    text = startYear.ToString() + "年 - " + (startYear + 11).ToString() + "年";
                }
                FCSize tSize = paint.textSize(text, font, -1);
                FCRect tRect = new FCRect();
                tRect.left = (width - tSize.cx) / 2;
                tRect.top = (height - tSize.cy) / 2;
                tRect.right = tRect.left + tSize.cx + 1;
                tRect.bottom = tRect.top + tSize.cy + 1;
                paint.drawText(text, getPaintingTextColor(), font, tRect, -1);
            }
        }
    }
}
